﻿//###HEADER###
//Title: RevitPlus
//Description of Program: Utilzing Revit geometry and properties, user is able to perform an EnergyPlus calculation within Revit.
//Class:UserInterface
//Description of Class: The user interface utilized in Revit. Contains catches in case floor or roof geometry is not available and in case room/zone is not available.
//       
//By: Steve Chick & Alexander Bernstein
//Date: 12/18/2012
//Version: 001

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;


namespace Revit_Addin1
{

    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]

    //Define Class
    public class UserInterface:IExternalCommand
    {
        public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            Autodesk.Revit.ApplicationServices.Application application = doc.Application;

            //Initialize material class and pass in commandData
            GetMaterialProperties matprops = new GetMaterialProperties();
            matprops.getmaterials(commandData);

            //Initialize zone class and pass in commandData
            GetZone getzones = new GetZone();
            getzones.getzones(commandData);

            Transaction trans = new Transaction(doc);
            if (trans.Start("Form") == TransactionStatus.Started)
            {
                //Check to ensure the project has rooms
                if (StoredVariables.Roomnames.Count != 0)
                {
                    //Check to ensure the project has floors and roofs
                    if(StoredVariables.FloorIndex.Count != 0 & StoredVariables.RoofIndex.Count != 0)
                    {
                        GetEplusVersions.get();

                        //Initialize form
                        BuildingForm building = new BuildingForm();
                        building.Show();
                    }
                        //Alert the user if no floor or roof geometry is found
                    else
                    {
                        TaskDialog.Show("RevitPlus: Geometry Error", "Floor or Roof Geometry is Missing. Please Check Model Before Proceeding", TaskDialogCommonButtons.Ok);
                    }
                }
                    //Alert the user if no rooms are found
                else
                {
                    TaskDialog.Show("RevitPlus: Geometry Error", "No Room Geometry Found. Please Define All Rooms", TaskDialogCommonButtons.Ok);
                }

                trans.Commit();
            }
            return Result.Succeeded;

        }
    }
}